﻿# CMakeList.txt: gitstore 的 CMake 项目，在此处包括源代码并定义
# 项目特定的逻辑。
#
cmake_minimum_required (VERSION 3.8)
#set(CMAKE_CXX_STANDARD 17)

set(COMPILE_CEPH true)

#set(CMAKE_BUILD_TYPE "Debug")
#set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -Wall -g2 -ggdb -fopenmp -ldl")
#set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -Wall -g2 -ggdb -fopenmp -ldl")

#set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "../build")
#set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "../build")


#add_definitions(-D _FILE_OFFSET_BITS=64)

#include_directories("/usr/local/include/etcd" "/usr/local/include/etcd/proto")
#link_directories("/usr/local/lib" "/usr/lib/x86_64-linux-gnu")
find_package(Boost REQUIRED COMPONENTS serialization)
find_package(OpenSSL REQUIRED)
find_library(ETCD_CPP_API_LIB etcd-cpp-api CMAKE_LIBRARY_PATH)
find_library(CRYPTO_LIB crypto CMAKE_LIBRARY_PATH)
find_library(JSONCPP_LIB jsoncpp CMAKE_LIBRARY_PATH)

add_library (GitStoreMeta SHARED "StoreObject.h" "StoreObject.cpp" "MetaObjectIO.h"
    "MetaObjectIO.cpp" "ObjectController.h" "ObjectController.cpp" "StoreObjectIO.h" "StoreObjectIO.cpp"
    "ErrorCode.h" "ErrorCode.cpp" "MetaObject.h"
    "MetaObjectOperation.h" "MetaObjectOperation.cpp"
    "Config.h" "Config.cpp" "Define.h" "PublicFunction.h" "PublicFunction.cpp"
    "StoreObjectDiff.h" "StoreObjectDiff.cpp" "StoreObjectMerge.h" "StoreObjectMerge.cpp" "ServiceImpl.h"
    "DatasetController.h" "DatasetController.cpp" "MetaObjectTrans.h" "MetaObjectTrans.cpp")

target_link_libraries(GitStoreMeta boost_serialization)

if (COMPILE_CEPH)
    add_definitions(-D COMPILE_CEPH)
    find_library(RADOS_LIB rados CMAKE_LIBRARY_PATH)
    if(NOT RADOS_LIB)
        message(FATAL_ERROR "rados lib not found!")
    else()
        target_link_libraries(GitStoreMeta rados)
    endif()
endif()

if(NOT OpenSSL_FOUND)
    message(FATAL_ERROR "ssl lib not found!")
else()
    target_link_libraries(GitStoreMeta ssl)
endif()

if(NOT ETCD_CPP_API_LIB)
    message(FATAL_ERROR "etcd-cpp-api lib not found!")
else()
    target_include_directories(GitStoreMeta PUBLIC "/usr/local/include/etcd" "/usr/local/include/etcd/proto")
    target_link_libraries(GitStoreMeta ${ETCD_CPP_API_LIB})
endif()

if(NOT CRYPTO_LIB)
    message(FATAL_ERROR "crypto lib not found!")
else()
    target_link_libraries(GitStoreMeta ${CRYPTO_LIB})
endif()

if(NOT JSONCPP_LIB)
    message(FATAL_ERROR "jsoncpp lib not found!")
else()
    target_link_libraries(GitStoreMeta ${JSONCPP_LIB})
endif()

# TODO: 如有需要，请添加测试并安装目标。
